#define _CRT_SECURE_NO_WARNINGS 1
#include "Stack.h"
void STInit(ST* st)
{
	assert(st && st->size);
	st->arr = NULL;
	st->capacity = st->size = 0;
}
void STPush(ST* st, STDateType value)
{
	assert(st);
	if (st->capacity == st->size)
	{
		int newCapacity = st->capacity == 0 ? 4 : 2 * st->capacity;
		STDateType* newArr = (STDateType*)realloc(st->arr,sizeof(STDateType) * newCapacity);
		if (newArr == NULL)
		{
			perror("realloc error!\n");
			exit(1);
		}
		st->arr = newArr;
		st->capacity = newCapacity;
	}
	*(st->arr + st->size++) = value;
}
void STPop(ST* st)
{
	assert(st);
	assert(st && st->size);
	st->size--;
}
STDateType STTop(ST* st)
{
	assert(st && st->size);
	return *(st->arr + st->size - 1);
}
bool STEmpty(ST* st)
{
	assert(st);
	return !st->size;
}
int STSize(ST* st)
{
	assert(st);
	return st->size;
}
void STDestroy(ST* st)
{
	assert(st);
	if (st->arr != NULL)
	{
		free(st->arr);
		st->arr = NULL;
	}
	st->capacity = st->size = 0;
}